<template>
  <div class="login_containger">
    
    <div class="login_box">
      <div class="avatar_box">
      <img src="../../assets/1000 (1).jpg" alt="" class="aa">
    </div>
    <!-- 登录表单区域 -->
    <el-form :model="loginForm" label-width="0px" class="login_from"  :rules="rules" ref="loginRef">
      <!-- 登录名 -->
      <el-form-item  prop="username" >
      <el-input v-model="loginForm.username" prefix-icon="iconfont icon-user" ></el-input>
     </el-form-item>
     <!-- 密码区 -->
     <el-form-item  prop="password">
      <el-input v-model="loginForm.password" prefix-icon="iconfont icon-3702mima" type="password"></el-input>
     </el-form-item>
     <!-- 按钮 -->
     <el-form-item  class="btns">
      <el-button type="primary" @click="login">登陆</el-button>
      <el-button type="info" @click="rest">重置</el-button>
     </el-form-item>
    </el-form>
    </div>
    
  </div>
</template>

<script>
import { login } from '../../api/user'
import {Message} from 'element-ui'
export default {
  name: "LoginIndex",
  methods: {
    async login() {
  
        await this.$refs.loginRef.validate();
        let res = await login(this.loginForm)
       console.log(res);
      if (res.meta.status !== 200) {
        Message.error(res.meta.msg)
      } else {
        Message.success('登录成功')
        this.$store.commit('user/token',res.data.token)
        this.$router.push('/welcome')
      }
      

     
   },
    rest() {
    this.$refs.loginRef.resetFields()
    },
  },
  data() {
    return {
      
        loginForm: {
        username: "admin",
        password: "123456",
      },
      rules:{ username:[ { required: true, message: '请输入用户名', trigger: 'blur' }],
        password: [{ min: 6, max: 13, message: '长度在 6 到 13个字符', trigger: 'blur' }
          , { required: true, message: '请输入密码', trigger: 'blur' }]
         },
     
    };
  },
};
</script>

<style lang="less" scoped>

.login_containger {
  position: relative;
  background-color: skyblue;
  height: 100vh;
  background: url(../../assets/1.jpeg);
}
.login_box {
  width: 450px;
  height: 350px;
  background-color: pink;
  border-radius: 3px;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%,-50%);
  opacity: .8;
  border-radius: 30px;
   
   
}
.avatar_box {
  height: 230px;
  width: 230px;
  border: 1px solid rgb(255, 255, 1);
  border-radius: 50%;
  padding: 10px;
  box-shadow:  0 0 35px rgb(255, 255, 1);
  position: absolute;
  left: 50%;
  transform: translate(-50%,-50%);
  background-color: rgb(237, 227, 227);
}
.avatar_box img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background-color: #eee ;
}

.btns  {
  display: flex;
  justify-content: flex-end;
}
  
  .login_from {
    position: absolute;
    bottom: 0;
    width: 100%;
    box-sizing: border-box;
    padding: 0 20px
    
  }
  .bb  h1 {
    position: absolute;
    top: 110px;
    left: 130px;
    color: greenyellow;
    font-size: 50PX;
  }

</style>
